# import matplotlib.pyplot as plt
# import numpy as np
#
# # 假设attention_weights是处理后得到的注意力权重矩阵
# attention_weights = np.random.rand(15, 15)  # 这里只是示例数据，实际需替换为真实权重
#
# plt.imshow(attention_weights, cmap='viridis')
# plt.xlabel('Sequence Position')
# plt.ylabel('Sequence Position')
# plt.colorbar()
# plt.title('Self - Attention Map')
# plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 方法名称
methods = ['DeepFM', 'LibFM', 'DKN', 'NPA', 'NAMl', 'LSTUR', 'NRMS', 'FIM', 'KRED', 'GnewRec', 'HieRec', 'DeepVT', 'MCCM', 'HGTS']
# AUC值
auc = [62.08, 62.04, 65.11, 66.21, 66.35, 67.13, 68.02, 67.62, 68.14, 67.72, 67.65, 69.35, 69.45, 69.71]
# MRR值
mrr = [30.11, 30.15, 31.76, 32.12, 32.82, 32.45, 33.36, 33.24, 33.25, 32.97, 32.51, 34.51, 34.41, 34.69]
# nDCG@5值
ndcg_5 = [31.51, 31.62, 33.53, 34.20, 35.21, 35.20, 36.51, 36.23, 36.76, 36.04, 36.55, 37.73, 37.62, 37.91]
# nDCG@10值
ndcg_10 = [37.31, 37.35, 39.35, 40.26, 41.68, 40.89, 42.21, 41.89, 42.33, 41.33, 41.74, 43.44, 43.31, 43.56]

x = np.arange(len(methods))
width = 0.2

fig, ax = plt.subplots()
rects1 = ax.bar(x - 1.5 * width, auc, width, label='AUC')
rects2 = ax.bar(x - 0.5 * width, mrr, width, label='MRR')
rects3 = ax.bar(x + 0.5 * width, ndcg_5, width, label='nDCG@5')
rects4 = ax.bar(x + 1.5 * width, ndcg_10, width, label='nDCG@10')

ax.set_ylabel('Performance')
ax.set_title('Performance Comparison of Different Methods')
ax.set_xticks(x)
ax.set_xticklabels(methods)
ax.legend()

def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
autolabel(rects4)

plt.show()